package com.acme;

import com.acme.bankapp.service.bank.BankService;
import com.acme.exceptions.NotEnoughFundsException;
import com.acme.exceptions.OverDraftLimitExceededException;

public class BankApplication {
	private final static String s0 = "The requested amount is: ";
	private final static String s1 = ", the max sum for amount is: ";
	private final static String s2 = "Not enough funds, need to use overdraft";
	private final static String serializeFile = "test/serialFile.txt";
	private final static String loadfeed = "-loadfeed";
	private final static String loadbank = "-loadbank";
	private final static String errCommandLine = "Wrong command line key";

	public static void main(String[] args) {
		BankService bankService = new BankService(serializeFile);

		if (args.length == 0) {
			return;
		}
		System.out.println(args[1]);
		if (args[0].equals(loadfeed)) {
			bankService.loader.read(args[1], bankService);
		} else if (args[0].equals(loadbank)) {
			bankService.readBank();
		} else {
			System.out.println(errCommandLine);
			return;
		}

		System.out.println();
		bankService.printBalance();
		System.out.println();

		try {
			bankService.modifyBank(bankService.bank.clients.get(0), 300, false);
		} catch (OverDraftLimitExceededException e) {
			System.out.println(s0 + e.getAmount() + s1 + e.getMaxSum());
		} catch (NotEnoughFundsException e) {
			System.out.println(s2);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println();

		try {
			bankService
					.modifyBank(bankService.bank.clients.get(1), 2100, false);

		} catch (OverDraftLimitExceededException e) {
			System.out.println(s0 + e.getAmount() + s1 + e.getMaxSum());
		} catch (NotEnoughFundsException e) {
			System.out.println(s2);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println();

		System.out.println();
		bankService.printBalance();
		System.out.println();

	}

}
